<?php
/**
 * VoteActive.class.php
 *
 * @author camfee <camfee@foxmail.com>
 * @date   18-1-2 下午9:17
 */

namespace Center;

use Common\ModuleBase;
use Common\Bridge;

class VoteActive extends ModuleBase
{
    protected static $_conf = [
        'db' => [
            'w' => Bridge::DB_CENTER_W,
            'r' => Bridge::DB_CENTER_R
        ],
        'table' => 'VoteActive',
        'fields' => [
            'Id' => self::VAR_TYPE_KEY,
            'CateId' => self::VAR_TYPE_INT,
            'Name' => self::VAR_TYPE_STRING,
            'Description' => self::VAR_TYPE_STRING,
            'Status' => self::VAR_TYPE_INT,
            'StartTime' => self::VAR_TYPE_STRING,
            'EndTime' => self::VAR_TYPE_STRING,
            'UpdateTime' => self::VAR_TYPE_STRING,
            'CreateTime' => self::VAR_TYPE_STRING,
        ],
        'mc' => Bridge::MEMCACHE_DEFAULT,
        // 可选, MC KEY, "KeyName:%d", %d会用主键ID替代
        'mckey' => 'VoteActive:%d',
        // 可选, 超时时间, 默认不过期
        'mctime' => 86400,
    ];

    const STATUS_NORMAL = 0;
    const STATUS_VOTE = 1;
    const STATUS_REWARD = 2;
    const STATUS_FINISH = 3;

    /**
     * 获取最新的有效投票活动
     *
     * @return array
     */
    public static function getLastValidActive()
    {
        $where = [
            'Status >=' => self::STATUS_VOTE,
            'Status <=' => self::STATUS_REWARD,
        ];
        $data = self::getList($where, 0, 1, '*', 'UpdateTime DESC');

        return !empty($data['data'][0]) ? $data['data'][0] : [];
    }

    /**
     * @see ModuleBase::add() 新增
     * @see ModuleBase::update() 更新
     * @see ModuleBase::getInfoByIds() 按id查询
     * @see ModuleBase::getList() 条件查询
     * @see ModuleBase::delete() 删除
     */

}